package startup

import (
	"context"
	"github.com/gin-gonic/gin"
	"shop-admin/routers"
	"shop-common/library/variables"
)

// RegisterHttpRoute 此处注册http接口
func RegisterHttpRoute() *gin.Engine {
	accessInfoLogger := &AccessInfoLogger{}
	accessErrLogger := &AccessErrLogger{}
	ginRouter := routers.InitWebRouter(accessInfoLogger, accessErrLogger)
	return ginRouter
}

type AccessInfoLogger struct{}

func (a *AccessInfoLogger) Write(p []byte) (n int, err error) {
	//variables.AccessLogger.Sugar().Info(context.Background(), "[gin-info] %s", p)
	variables.Logger.Infof(context.Background(), "[gin-info] %s", p)
	return 0, nil
}

type AccessErrLogger struct{}

func (a *AccessErrLogger) Write(p []byte) (n int, err error) {
	//variables.AccessLogger.Sugar().Error(context.Background(), "[gin-err] %s", p)
	variables.Logger.Errorf(context.Background(), "[gin-err] %s", p)
	return 0, nil
}
